home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / msn / MSNObject.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  6KB  |  157 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import hashlib
  5. import util
  6. import msn
  7. from logging import getLogger
  8. log = getLogger('msn.object')
  9.  
  10. class MSNObject(object):
  11.     __slots__ = 'creator size type location friendly sha1d sha1c\n                _friendly _sha1d _sha1c stamp _stamp contenttype contentid avatarid\n                avatarcontentid _avatarcontentid _xml'.split()
  12.     EUF = '{A4268EEC-FEC5-49E5-95C3-F126696BDBF6}'
  13.     types = {
  14.         '2': 'emoticons',
  15.         '3': 'icon',
  16.         '5': 'bg_image',
  17.         '8': 'wink',
  18.         '11': 'sound',
  19.         '12': 'state' }
  20.     
  21.     def __init__(self, Creator, Type, Location, Size, SHA1D, Friendly = u'\x00', SHA1C = None, contenttype = None, contentid = None, stamp = None, avatarid = None, avatarcontentid = None):
  22.         object.__init__(self)
  23.         self.creator = Creator
  24.         self.type = Type
  25.         self.size = Size
  26.         self.location = Location
  27.         self._sha1d = SHA1D
  28.         self._friendly = Friendly
  29.         if not SHA1C:
  30.             pass
  31.         self._sha1c = self.calc_sha1c()
  32.         self._stamp = stamp
  33.         self._avatarcontentid = avatarcontentid
  34.         self.contenttype = contenttype
  35.         self.contentid = contentid
  36.         self.avatarid = avatarid
  37.         self._xml = None
  38.  
  39.     
  40.     def get_sha1d(self):
  41.         return self._sha1d.encode('base-64').strip()
  42.  
  43.     
  44.     def set_sha1d(self, new_val):
  45.         self._sha1d = new_val.decode('base-64')
  46.  
  47.     
  48.     def get_friendly(self):
  49.         return self._friendly.encode('utf-16-le').encode('base-64').strip()
  50.  
  51.     
  52.     def set_friendly(self, new_val):
  53.         self._friendly = new_val.decode('base-64').decode('utf-16-le')
  54.  
  55.     
  56.     def calc_sha1c(self):
  57.         to_hash = 'Creator%sSize%sType%sLocation%sFriendly%sSHA1D%s' % (self.creator, self.size, self.type, self.location, self.friendly, self.sha1d)
  58.         return hashlib.sha1(to_hash).digest()
  59.  
  60.     
  61.     def get_sha1c(self):
  62.         return self.calc_sha1c().encode('base-64').strip()
  63.  
  64.     
  65.     def set_sha1c(self, new_val):
  66.         if new_val != self.sha1c:
  67.             raise ValueError, 'SHA1C hash is not correct'
  68.         
  69.  
  70.     
  71.     def get_stamp(self):
  72.         return None if self._stamp is None else self._stamp.encode('base-64').strip()
  73.  
  74.     
  75.     def set_stamp(self, new_val):
  76.         if new_val is None:
  77.             self._stamp = None
  78.         else:
  79.             self._stamp = new_val.decode('base-64')
  80.  
  81.     
  82.     def get_avatarcontentid(self):
  83.         return None if self._avatarcontentid is None else msn.util.base64_encode(self._avatarcontentid)
  84.  
  85.     
  86.     def set_avatarcontentid(self, new_val):
  87.         if new_val is None:
  88.             self._avatarcontentid = None
  89.         else:
  90.             self._avatarcontentid = msn.util.base64_decode(new_val)
  91.  
  92.     friendly = property(get_friendly, set_friendly)
  93.     sha1d = property(get_sha1d, set_sha1d)
  94.     sha1c = property(get_sha1c, set_sha1c)
  95.     stamp = property(get_stamp, set_stamp)
  96.     avatarcontentid = property(get_avatarcontentid, set_avatarcontentid)
  97.     
  98.     def to_xml(self):
  99.         if self._xml is None:
  100.             t = util.tag('msnobj')
  101.             t._attrs = util.odict()
  102.             t._attrs['Creator'] = self.creator
  103.             t._attrs['Size'] = self.size
  104.             t._attrs['Type'] = self.type
  105.             t._attrs['Location'] = self.location
  106.             t._attrs['Friendly'] = self.friendly
  107.             t._attrs['SHA1D'] = self.sha1d
  108.             t._attrs['SHA1C'] = self.sha1c
  109.             xml = t._to_xml(pretty = False).strip()
  110.             xml = xml[:-3] + '/>'
  111.             self._xml = xml
  112.         
  113.         return self._xml
  114.  
  115.     
  116.     def __ne__(self, other):
  117.         return not self.__eq__(other)
  118.  
  119.     
  120.     def __eq__(self, other):
  121.         
  122.         try:
  123.             for attr in ('creator', 'size', 'type', 'location', 'sha1d'):
  124.                 mine = getattr(self, attr)
  125.                 theirs = getattr(other, attr)
  126.                 if getattr(self, attr) != getattr(other, attr):
  127.                     return False
  128.                     continue
  129.         except AttributeError:
  130.             e = None
  131.             return False
  132.  
  133.         return True
  134.  
  135.     
  136.     def parse(cls, xml):
  137.         t = util.tag(xml)
  138.         o = cls(**t._attrs)
  139.         o.stamp = t._attrs.get('stamp', None)
  140.         o.avatarcontentid = t._attrs.get('avatarcontentid', None)
  141.         (o.friendly, o.sha1d) = [ t[k] for k in [
  142.             'Friendly',
  143.             'SHA1D'] ]
  144.         
  145.         try:
  146.             o.sha1c = t['SHA1C']
  147.         except:
  148.             []
  149.             []
  150.             o.sha1c = o.sha1c
  151.  
  152.         o._xml = xml
  153.         return o
  154.  
  155.     parse = classmethod(parse)
  156.  
  157.